package com.erik.lin.collect;

import com.erik.lin.domain.DbInfo;
import lombok.SneakyThrows;
import org.apache.ibatis.builder.xml.XMLMapperBuilder;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;

import java.io.IOException;

/**
 * Created by Erik on 2018/2/9.
 */
public class OracleCollectAdapter extends CollectAdapter {

    public OracleCollectAdapter(DbInfo dbInfo) {
        super(dbInfo);
    }

    private void initializeMysqlProperties(DbInfo dbInfo){
        String userName = dbInfo.getParam().get("userName");
        dbInfo.getParam().put("tableSchema", userName);
    }

    @Override
    @SneakyThrows(IOException.class)
    public void initializeSqlSessionFactory(DbInfo dbInfo) {
        Configuration configuration = getConfiguration(dbInfo);
        Resource resource = new PathMatchingResourcePatternResolver().getResource("classpath:collect/OracleCollectMapper.xml");
        XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(resource.getInputStream(), configuration, resource.toString(), configuration.getSqlFragments());
        xmlMapperBuilder.parse();
        super.sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
    }
}